import { Chessman } from "./Chessman";

export default class ChessElephant extends Chessman {
  constructor(chessName, camp, x, y, key, chessId) {
    super(chessName, camp, x, y, key, chessId);
  }
  predictionMove(chessList, path?) {
    const res = [];
    const temp = [];
    {
      temp.push(
        ...[
          [this.x + 2, this.y - 2],
          [this.x - 2, this.y - 2],
          [this.x + 2, this.y + 2],
          [this.x - 2, this.y + 2],
        ]
      );
      if (this.camp === "red") {
        if (this.y - 2 < 5) {
          temp[0] = null;
          temp[1] = null;
        } else if (this.y + 2 > 9) {
          temp[2] = null;
          temp[3] = null;
        }
      }
      if (this.camp === "black") {
        if (this.y + 2 > 5) {
          temp[2] = null;
          temp[3] = null;
        } else if (this.y - 2 < 0) {
          temp[0] = null;
          temp[1] = null;
        }
      }
      chessList.forEach((chessman) => {
        // 判断象脚
        if (
          (this.x + 1 === chessman.x || this.x - 1 === chessman.x) &&
          (this.y - 1 === chessman.y || this.y + 1 === chessman.y)
        ) {
          if (this.x + 1 === chessman.x && this.y + 1 === chessman.y) {
            temp[2] = null;
          }
          if (this.x + 1 === chessman.x && this.y - 1 === chessman.y) {
            temp[0] = null;
          }
          if (this.x - 1 === chessman.x && this.y - 1 === chessman.y) {
            temp[1] = null;
          }
          if (this.x - 1 === chessman.x && this.y + 1 === chessman.y) {
            temp[3] = null;
          }
        }
      });
      if (this.x - 2 < 0) {
        temp[1] = null;
        temp[3] = null;
      } else if (this.x + 2 > 8) {
        temp[0] = null;
        temp[2] = null;
      }
    }
    res.push(...this.filterChessman(temp, [...chessList]));
    return { data: this, path: res };
  }
}
